<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>展开语法</title>
</head>
<body>
    <script>
        let arr = ['abc','def'];
        let arr1 = ['ghi','jkl'];
        // for (const value of arr1) {
        //     arr.push(value);
        // }

        // 用展开语法将两个数组合并成一个数组
        arr = [...arr,...arr1];
        console.log(arr);


        // 用展开数组求和运算
        function sum(...args){
            return args.reduce((s,v) => {
                return s += v;
            },0);
        }

        // array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
        //total和, currentValue当前的值, initialValue初始值
        
        console.log(sum(1,2,3));
    </script>
</body>
</html>